package com.store.control;

import java.io.IOException;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.context.ApplicationContext;

import com.store.application.Order;
import com.store.application.Store;
import com.store.view.SpringContext;

/**
 * Servlet implementation class TraitementRechercheOrdres
 */
public class TraitementRechercheOrdres extends HttpServlet {
	private static final long serialVersionUID = 1L;
	Store store;
       
    /**
     * @see HttpServlet#HttpServlet()
     */
    public TraitementRechercheOrdres() {
        super();
        ApplicationContext context = SpringContext.getApplicationContext();
        store =  (Store)context.getBean("store");
    }

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		
		// je vais recuperer les parametres du formulaire
		 if (request.getParameter("allOrders") != null) {
			 
			 List<Order> orders = store.getAllOrders();
				request.setAttribute("orders", orders);
				request.getRequestDispatcher("JSP/basic/resultSearchOrders.jsp").forward(request,response);
		        

		    } else if (request.getParameter("ordresByContractType") != null) {
		          // l'utilisateur veut des societ�s par nom
		    	
		    } else if (request.getParameter("OrdersByDate") != null) {
		          // l'utilisateur veut des societ�s par nom
		    	
		    } else {
		    	// redirige vers une page d'erreur ou la page de la recherche.
		    }

		
	}

}
